package mianshi.huawei.medium;

import java.util.Scanner;

public class 字符串通配符 {
    public static void main(String[] args) {
        /*Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str1 = scanner.next();
            String str2 = scanner.next();
            System.out.println(test(str1, str2));
        }*/
        System.out.println(test("wl*sgdvletkst", "wltsgdvletkst"));
       /* String substring = "helloworld".substring(4);
        System.out.println(4+substring.lastIndexOf("o"));*/

    }

    public static boolean test(String str, String str2) {
        /** abc?*t
         *  abcdadilhatl;nmnt
         *
         */
        int str2Index = 0;//当前匹配字符串的字符的下标
        for (int i = 0; i < str.length(); i++, str2Index++) {

            char c1 = str.charAt(i);
            if (c1 == '?') {

            } else if (c1 == '*') {
                if (i == str.length() - 1) {
                    return true;
                } else {
                    i++;
                    c1 = str.charAt(i);
                    String substring = str2.substring(str2Index);
                    if (!substring.contains(c1 + "")) {
                        return false;
                    } else {
                        int num = substring.lastIndexOf(c1);
                        if (num != 0) {

                            str2Index = str2Index + num;
                        }
                    }
                }

            } else {
                char c2 = str2.charAt(str2Index);
                if (c1 != c2) {
                    return false;
                }
            }


        }


        return true;
    }
}
